package game.entity;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import game.ability.AbilityManager;
import game.ability.AbsAbility;
import game.ability.MovingLeft;
import game.helper.ArmyBoundary;
import game.particles.AbsParticle;
import game.particles.Particle_1;
import game.shared.Constants;

public class Monster extends AbsSprite {

	AbsParticle waterParticle;
	boolean attack = false;
	AbilityManager abilityManager;
	int count;
//	Sound shot;
	
	public Monster(Monster monster){
		super(monster);
		Constants.MONSTER_NUMBER++;
		waterParticle = new Particle_1(Constants.PARTICLE_SPRING_WATER_P1, Constants.PARTICLE_SPRING_WATER_P2);
		count = 0;
		this.abilityManager = monster.abilityManager;
//		shot = Gdx.audio.newSound(Gdx.files.internal("res/sound/shot.mp3"));
	}
	
	public Monster(SpriteManager _SpriteManager, String imgPath, int idAnimation, float frameDuration, int num_rows, int num_clus) {
		super(_SpriteManager, imgPath,idAnimation,  frameDuration,  num_rows, num_clus);
		waterParticle = new Particle_1(Constants.PARTICLE_SPRING_WATER_P1, Constants.PARTICLE_SPRING_WATER_P2);
	}
	
	public Monster(SpriteManager _SpriteManager, String imgPath,int idAnimation, float frameDuration, int scrX, int scrY, int frameWidth, int frameHeight, int num_rows, int num_clus) {
		super(_SpriteManager, imgPath,idAnimation,  frameDuration,  scrX, scrY, frameWidth, frameHeight, num_rows, num_clus);
		waterParticle = new Particle_1(Constants.PARTICLE_SPRING_WATER_P1, Constants.PARTICLE_SPRING_WATER_P2);
	}	
	
	public Monster(AbilityManager abilityManager, SpriteManager _SpriteManager, String configueFilePath)
	{
		super(_SpriteManager, configueFilePath);
		waterParticle = new Particle_1(Constants.PARTICLE_SPRING_WATER_P1, Constants.PARTICLE_SPRING_WATER_P2);
		this.abilityManager = abilityManager;
	}
	
	@Override
	public void update() {
		attack = false;
		for(int i=0; i<spriteMamanger.count(); i++)
		{
			//if(this.getBoundingRectangle().overlaps(spriteMamanger.getByIndex(i).getBoundingRectangle())){
			float y = this.getY();
			if(this.getX() <= ArmyBoundary.getX(y))
			{
				attack = true;
			}
		}
		if(attack == true){
			this.setState(Constants.SPRITE_ATTACK_LEFT);
			this.setMoving(null);
		}
		
		super.update();
		
		if (waterParticle != null)
			waterParticle.setPosition((int)getX(), (int)getY());
		if(this.getCurrentState() == Constants.SPRITE_ATTACK_LEFT){
//			for(int i=0; i<spriteMamanger.count(); i++){
//				spriteMamanger.getByIndex(i).setHp(spriteMamanger.getByIndex(i).getHp() - 0.01f);
//			}
		}
		
//		count++;
//		if	(count>100){
//			AbsAbility shot_1 = new Ammunition(spriteMamanger, this.getX(), this.getY());
//			abilityManager.add(shot_1);
//			//shot.play();
//			count = 0;
//		}
	}	


	@Override
	public void render(SpriteBatch spriteBatch) {
		if (waterParticle != null)
			waterParticle.render(spriteBatch);
		super.render(spriteBatch);
		
	}

	public Monster(AbsSprite monster)
	{
		super(monster);
	}
}
